<template>
	<view>
		<baseHead title="企业视频" bg="#ffffff" color="#000000" :text_right="title" :right="true" @clickRight="clickRight">
		</baseHead>
		<view>
			<view style="padding: 20rpx;">
				<view v-for="(item,index) in videolist" style="position: relative;" v-if="videolist">
					<video :src="item" style="width: 664rpx; height: 350rpx; margin:0rpx 20rpx;border-radius: 20rpx;"
						:object-fit="cover" :show-center-play-btn="true"></video>
					<view v-if="urlType != 2" style="position: absolute; top: 0; right: -10rpx;"
						@click="deletePicuploadAvatar(item,index)">
						<u-icon name="close" color="#000"></u-icon>
					</view>
				</view>

				<view style=" margin:20rpx;" v-if="videolist.length<3">
					<u-upload accept="video" @afterRead="uploadAvatar" name="5" :maxCount="1" :previewFullImage="true"
						v-if="show"></u-upload>

				</view>

			</view>
		</view>
	</view>
</template>

<script>
	import baseHead from '@/pages/component/baseHead.vue'
	export default {
		data() {
			return {
				URL: this.$config.domain.staticUrl,
				GoodAtVideo: [],
				cover: "",
				model: {
					PhotoPaths: "",
				},
				show: true,
				title: "保存",
				uploadIconColor: '#D3D4D6',
				urlType: '',
			}
		},
		components: {
			baseHead
		},
		onLoad(option) {
			console.log(option, '数据--------')
			this.urlType = option.type
			if (option.type) {
				this.show = false
				this.title = ""
			} else {
				this.show = true
				this.title = "保存"
			}
		},
		created() {
			this.listdata();
		},

		computed: {

			videolist() {
				if (this.GoodAtVideo) {
					return this.GoodAtVideo.map(res => {
						return this.URL + res.VideoPath
					})
				}

			}
		},
		methods: {
			// 删除视频
			deletePicuploadAvatar(item, index) {
				this.GoodAtVideo.splice(index, 1);
				console.log(this.GoodAtVideo);

			},
			listdata() {
				let qyid = uni.getStorageSync('dianjiqiye');
				this.$http.core.tenantgetall(qyid.Id).then(res => {
					if (res.Success) {
						this.model = res.Result;
						console.log(res.Result);
						// console.log(JSON.parse(res.Result.VedioPaths));	
						if (res.Result.CorpVideo) {
							this.GoodAtVideo = res.Result.CorpVideo;
						}

						console.log(this.GoodAtVideo);
					}
				})
			},
			clickRight() {
				console.log(this.GoodAtVideo);
				this.model.CorpVideo = this.GoodAtVideo
				console.log(this.model);
				//修改
				this.$http.core.tenantupdate(this.model).then(res => {
					if (res.Success) {
						this.$util.toast("修改成功")
						setTimeout(() => {
							uni.navigateBack();
						}, 1000)
					}
				})
			},

			//上传 视频
			uploadAvatar(file, lists, name) {
				console.log(file);
				console.log(lists);
				console.log(name);
				let that = this;
				let tempFilePaths = file.file
				if (Number(tempFilePaths.size) > this.videomaxsize) {
					console.log("22222");
					this.$util.toast("视频最大上传300M")
					console.log(1024 * 1024 * 300);
					console.log(tempFilePaths.size > this.videomaxsize);
					return
				} else {
					console.log("1111111");
					let obj = {
						src: tempFilePaths.url
					}
					console.log(obj);
					that.$util.AuploadFile(obj).then(res => {
						console.log(res);
						if (res.Success) {
							console.log(res.Result);
							// that.src = res.Result.Path;
							let obj = {
								VideoPath: res.Result.Path
							}
							that.GoodAtVideo.push(obj)
							console.log(that.GoodAtVideo);
						}
					})
				}


				// uni.uploadFile({
				// 	url: that.$config.domain.baseUrl + "/api/core/file/upload",
				// 	filePath: tempFilePaths.url,
				// 	name: "file",
				// 	header: {
				// 		'Authorization': uni.getStorageSync("access_token").token_type + " " +
				// 			uni.getStorageSync("access_token").access_token,
				// 	},
				// 	success: function(res) {
				// 		if (res.statusCode == 200) {
				// 			let data = JSON.parse(res.data)
				// 			if (data.Success) {
				// 				console.log(data.Result.Path)
				// 				console.log(data.Result);
				// 				that.GoodAtVideo.push(data.Result.Path)
				// 			}
				// 		}
				// 	}
				// })
			},

		}
	}
</script>

<style scoped lang="scss">
	/deep/.uni-video-controls {
		margin: 0 !important;
	}

	/deep/ .uni-video-bar {
		padding: 0 !important;
	}
</style>